package semantic_matching.common.schema;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.MatchQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by julianzliu on 4/25/2017.
 */


public class MatchedDocumentTree {
    /*
    保存匹配的  文档  集合
     */

    public List<MatchedEntityTree>  matchedEntityTreeList;

    public MatchedDocumentTree(){
        this.matchedEntityTreeList = new ArrayList<>();
    }

    public void addMatchedEntityTree(MatchedEntityTree tree){
        this.matchedEntityTreeList.add( tree );
    }


    public JsonNode genJsonResult(){
        ObjectMapper mapper = new ObjectMapper();
        ObjectNode node = mapper.createObjectNode();

        for(MatchedEntityTree entityTree: matchedEntityTreeList){
            ArrayNode treeEntities = mapper.createArrayNode();
            MatchedEntites rootEntites = entityTree.rootEntities;
            for(String entity: rootEntites.entities){
                treeEntities.add(entity);
            }
            String key = (new Integer(entityTree.entityTree.hashCode())).toString();
            node.put(key , treeEntities );
        }
        return node;
    }

}
